Skip to content

feat: using websockets events for transaction polling#7822

Open
jpuri wants to merge 21 commits intomainfrom
transaction_polling_improvements
Open

feat: using websockets events for transaction polling#7822
jpuri wants to merge 21 commits intomainfrom
transaction_polling_improvements

Conversation

@jpuri
Copy link
Contributor

@jpuri jpuri commented Feb 3, 2026

Explanation

Using event AccountActivityService:transactionUpdated to improve transaction polling.

References

Fixes https://github.com/MetaMask/MetaMask-planning/issues/6948

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Changes core transaction polling behavior by introducing a new event-driven trigger and additional filtering logic (chain/account/hash/status), which could affect how quickly transactions update or how often polling runs if the event stream is noisy or mismatched.

Overview
Adds event-driven pending transaction polling by having TransactionPoller subscribe to AccountActivityService:transactionUpdated and trigger an immediate poll when an update matches the current chainId, is a terminal status (confirmed/dropped/failed), is from the selected account, and corresponds to a currently pending tx hash.

Refactors CAIP-2 chain-id conversion into a shared caip2ToHex utility (used by both TransactionPoller and IncomingTransactionHelper) and adds unit coverage for the new websocket trigger behavior and CAIP parsing; changelog is updated to announce the new polling mode.

Written by Cursor Bugbot for commit bec1c47. This will update automatically on new commits. Configure here.

@jpuri jpuri requested a review from a team as a code owner February 3, 2026 15:00
@jpuri jpuri force-pushed the transaction_polling_improvements branch from 70ae62d to 41a0567 Compare February 3, 2026 15:22
@jpuri jpuri requested a review from a team as a code owner February 3, 2026 15:22
@jpuri jpuri enabled auto-merge February 3, 2026 15:25
@jpuri jpuri force-pushed the transaction_polling_improvements branch from e9cf4eb to 45493b2 Compare February 3, 2026 15:59
return;
}

if (transaction.status !== 'confirmed') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also want to continue if failed so we can check the receipt and update the status to failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, let me add that.

Copy link
Contributor Author

@jpuri jpuri Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is updated to check for both dropped and failed statuses also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afraid I can't see this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh something I missed with opencode, let me check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is updated

return;
}

if (transaction.status !== 'confirmed') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check the from of the transaction to confirm it's an outgoing transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me update the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this change as it is failing for some transactions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we isolate why? I worry if we got lots of incoming transactions, or spam ones, it might cause excessive requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of smart transactions or when from / to is not same as what is submitted.

Subscription will be done only if there are pending requests for that chain thus the probability of an incoming transaction causing a request is low.

But I agree there should be some way to map this update to a pending transaction to confirm that it is not incoming, let me check this more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that in data returned by transaction updated event the transaction id is same as transaction hash, this can be used to find pending transaction and use its from address:

Screenshot 2026-02-06 at 10 17 26 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added check to see if that transaction update received is for one of pending transactions

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@jpuri jpuri requested a review from matthewwalsh0 February 4, 2026 14:39
enum IntervalTrigger {
Accelerated = 'Accelerated',
BlockTracker = 'BlockTracker',
TransactionUpdate = 'TransactionUpdate',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, maybe Websocket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is updated

return;
}

if (transaction.status !== 'confirmed') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afraid I can't see this one?

return;
}

if (transaction.status !== 'confirmed') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we isolate why? I worry if we got lots of incoming transactions, or spam ones, it might cause excessive requests?

@jpuri jpuri requested a review from matthewwalsh0 February 6, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants